package com.wjbgn.electronicnian.convert;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wjbgn.electronicnian.dto.NianUserDTO;
import com.wjbgn.electronicnian.entity.NianUserDO;
import com.wjbgn.electronicnian.util.BeanCopierUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Description: 
 * Create Date: 2022-01-20T11:06:12.883426600
 * @author weirx
 * @version 1.0
 */
@Component
public class NianUserDoConvert {

    /**
     * DtoToDo
     *
     * @param nianUserDTO
     * @return
     */
    public static NianUserDO dtoToDo(NianUserDTO nianUserDTO) {
            NianUserDO nianUserDO = new NianUserDO();
        BeanCopierUtil.copy(nianUserDTO, nianUserDO);
        return nianUserDO;
    }

    /**
     * DoToDto
     *
     * @param nianUserDO
     * @return
     */
    public static NianUserDTO doToDto(NianUserDO nianUserDO) {
            NianUserDTO nianUserDTO = new NianUserDTO();
        BeanCopierUtil.copy(nianUserDO, nianUserDTO);
        return nianUserDTO;
    }

    /**
     * Page<DO> to Page<DTO>
     *
     * @param pageDO
     * @return
     */
    public static Page<NianUserDTO> pageConvert(Page<NianUserDO> pageDO) {
        List<NianUserDTO> list = listConvert(pageDO.getRecords());
        Page<NianUserDTO> page = new Page<>(pageDO.getCurrent(), pageDO.getSize(), pageDO.getTotal());
        page.setRecords(list);
        return page;
    }

    /**
     * list<DO> to list<DTO>
     *
     * @param listDO
     * @return
     */
    public static List<NianUserDTO> listConvert(List<NianUserDO> listDO) {
        List<NianUserDTO> list = new ArrayList<>();
            NianUserDTO nianUserDTO;
        for (NianUserDO nianUserDO : listDO) {
                nianUserDTO = new NianUserDTO();
            BeanCopierUtil.copy(nianUserDO, nianUserDTO);
            list.add(nianUserDTO);
        }
        return list;
    }
}